﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection.Emit;
using System.Text;
using System.Reflection;
using LinFu.IoC.Configuration;

namespace CoreEx.DynamicInvoker.Implementation
{
    [Implements(typeof(IDynamicFactory<MethodInfo>),LifecycleType.OncePerRequest)]
    public class MethodFactory : MethodFactoryBase<MethodInfo>
    {       
        protected override void EmitMethodBody(ILGenerator ilGenerator, MethodInfo target)
        {                                 
            var callInstruction = target.IsVirtual ? OpCodes.Callvirt : OpCodes.Call;
            ilGenerator.Emit(callInstruction, target);                       
        }

        public override Type GetReturnType(MethodInfo member)
        {
            return member.ReturnType;
        }
    }   
}
